<template>
	<view class=" ">
		<u-popup v-model="wcshow" mode="center" border-radius="32">
			<view class="popupmd text_center">
				<view class="font_16_333 font_weight">
					服务时间已到
				</view>
				<view class="font_12_666 u-m-t-20">
					服务时间已到，自动离线
				</view>
				<view class="p-bd u-m-t-50 flex flex_sb">
					<view class="p-btn1" @click="tosetting">
						去设置
					</view>
					<view class="p-btn2" @click="wcshow=false">
						确定
					</view>
				</view>
			</view>
		</u-popup>
		
		<u-popup v-model="wcshow2" mode="center" border-radius="32">
			<view class="popupmd text_center">
				<view class="font_16_333 font_weight">
					请设置服务时间
				</view>
				<view class="font_12_666 u-m-t-20">
					请设置服务时间
				</view>
				<view class="p-bd u-m-t-50 flex flex_sb">
					<view class="p-btn1" @click="tosetting">
						去设置
					</view>
					<view class="p-btn2" @click="wcshow2=false">
						取消
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wcshow:false,
				wcshow2:false
			}
		},
		
		created() {
			if(!uni.getStorageSync("serverTimeShow")){
				this.getservetime()
			}
			
		},

		methods: {
			tosetting(){
				this.wcshow=false
				this.wcshow2=false
				uni.navigateTo({
					url:"/subPackageA/pages/lawyerVersion/mine/setting"
				})
			},
			getservetime(){
				let date = new Date();
				let month = date.getMonth()
				this.$api({
					url: '/lawyer/time_config',
					method: 'get',
					data: {
						token: uni.getStorageSync("token"),
						month:month+1,
					},
				}).then(res => {
					if (res.data) {
						if(res.data.length==0){
							this.wcshow2 = true
							uni.setStorage({
								key: 'serverTimeShow',
								data: 1
							});
							return
						}
						
						let timeList = res.data[0].end_time
						
						let nowtime = new Date().getTime()
						let onetime = new Date(this.getCurrentDate(timeList)).getTime()
						console.log(this.getCurrentDate(timeList))
						console.log(nowtime,onetime)
						if (nowtime > onetime) {
							this.wcshow = true
							uni.setStorage({
								key: 'serverTimeShow',
								data: 1
							});
						} else {
							
						  // let t = (onetime - nowtime)
						  // console.log(t/1000)
						  // setTimeout(() => {
						  //   //要执行的方法
						  // }, t)
						}
						
						
					}
				})
			},
			//获取某个时间的时间戳   
			 getCurrentDate(time) {
			      let now = new Date();
			      let year = now.getFullYear();
			      let month = now.getMonth() + 1;
			      let day = now.getDate();
			      return year + "/" + month + "/" + day + ' ' + time
			  },
			 
			
		}
	}
</script>

<style scoped lang="scss">
	.popupmd{
		width: 554rpx;
		// height: 344rpx;
		background: linear-gradient( 180deg, #FFECEA 0%, #FFFFFF 100%);
		padding: 68rpx 24rpx;
		
		.fz-icon{
			width: 24rpx;
			height: 24rpx;
			margin-left: 20rpx;
		}
		
		&2{
			padding: 48rpx;
		}
		.p-bd{
			font-size: 28rpx;
			line-height: 64rpx;
			text-align: center;
			.p-btn1{
				width: 248rpx;
				height: 64rpx;
				background: #FFFFFF;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				border: 2rpx solid #D6D6D6;
				
				color: #9695A3;
			}
			.p-btn2{
				width: 248rpx;
				height: 64rpx;
				background: linear-gradient( 180deg, #FA2D2D 0%, #F40000 100%);
				border-radius: 46rpx 46rpx 46rpx 46rpx;
				color: #FFFFFF;
			}
		}
		
		
	}
</style>